﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Bymed.SpineScan.Service.Validation
{
    public static class ValidationHelper
    {
        /// <summary>
        /// To check whether the input content is empty or not.
        /// </summary>
        /// <param name="content">The input content</param>
        /// <returns>True means Pass. False means Fail.</returns>
        public static bool RuleCheckRequiredContent(string content)
        {
            if (content == null)
            {
                return false;
            }
            else
            {
                return string.IsNullOrEmpty(content.Trim()) ? false : true;
            }
        }

        /// <summary>
        /// To check whether the input content length exceed the provided max value.
        /// </summary>
        /// <param name="max">The max value.</param>
        /// <param name="currentValue">The input content to be validated.</param>
        /// <returns>True means Pass. False means Fail.</returns>
        public static bool RuleCheckMaxLength(int max, string content)
        {
            if (RuleCheckRequiredContent(content) && content.Length > max)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        /// <summary>
        /// To check whehter the input value is a positive integer.
        /// </summary>
        /// <param name="inputValue">The input value.</param>
        /// <returns>True means Pass. False means Fail.</returns>
        public static bool RuleCheckPositiveInteger(string inputValue)
        {
            var pattern = "^[0-9]+$";

            if (Regex.IsMatch(inputValue, pattern, RegexOptions.Compiled))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// To check whehter the input value is a valid date format.
        /// </summary>
        /// <param name="dateTime">Datetime string to be validated.</param>
        /// <returns>True means Pass. False means Fail.</returns>
        public static bool RuleCheckValidDate(string inputValue)
        {
            try
            {
                DateTime.Parse(inputValue);
                return true;
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// To check whether the current value is in the provided range.
        /// </summary>
        /// <param name="min">The min value of the range.</param>
        /// <param name="max">The max value of the range.</param>
        /// <param name="currentValue">The current value to be validated.</param>
        /// <returns>True means Pass. False means Fail.</returns>
        public static bool RuleCheckRange(int min, int max, int currentValue)
        {
            if (currentValue < min || currentValue > max)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}
